package TransactionImplementation

import (
	"SalaryPayment/DataBase"
	"SalaryPayment/ModelImplementation"
	"fmt"
	"log"
	"reflect"
	"strconv"
	"time"
)

type SalesReceiptTransaction struct {
	itsEmpid     int
	itsSalesDate time.Time
	itsAmount    float64
}

func (srt *SalesReceiptTransaction) Execute() {
	e := DataBase.PayrollDatabase.GetEmployee(srt.itsEmpid)

	if e != nil {
		pc := e.GetClassification()

		if reflect.TypeOf(pc) == reflect.TypeOf(ModelImplementation.CommissionClassification{}) {
			cc := pc.(*ModelImplementation.CommissionClassification)
			sr := ModelImplementation.NewSalesReceipt(srt.itsSalesDate, srt.itsAmount)
			cc.AddSalesReceipt(sr)
		} else {
			log.Println(fmt.Errorf(DataBase.PayrollExceptionMessage.NotCommissionedClassification +
				strconv.Itoa(e.GetEmpid())))
		}
	} else {
		log.Println(fmt.Errorf(DataBase.PayrollExceptionMessage.EmployeeNotExist + strconv.Itoa(e.GetEmpid())))
	}
}
